var superagent = require("superagent");
require('es6-promise').polyfill();
var request = require('superagent-promise-plugin').patch(superagent);

var host = "139.129.42.180:5000";
var prefix = (url) => {
    return `${host}/intel${url}`;
};
var arr = ["000","001","010","011","100","101","110","111"];
var c = 0;
// setInterval(function(){
//     c ++;
//     request
//         .post(prefix("/setState"))
//         .send({equipment: "intelPatch"})
//         .send({type : "state"})
//         .send({value : arr[c % 6]})
//         .then(function(res){
//             console.log(res.text);
//         });
// },3000);


var Client = require("./index");
var config = require("./config.json");
var server = config.server;
var client = new Client(server.host,server.port,server.name,server.pin);
client.Start().then(function(){
    client.socket.on("disconnect",function(){
        console.log("disconnect from server");
        client.socket.disconnect();
    });
});


var phoneClient = new Client(server.host,server.port,"phone","123");
phoneClient._Login().then(function(){

    phoneClient.socket.on("phoneDoorBell",function(data){
        console.log(data);
    });
    phoneClient.socket.on("phoneBody",function(data){
        console.log(data);
    });

});